#coding=utf-8
'''
Created on 2013年7月29日

@author: xuben

登录游戏
'''

from ..common import Command, GameConfig, SocketService
from ..common.SocketService import gameSocketService

'''
登录
@param reconnect: 是否重连
'''
def login(reconnect):
    if reconnect:
        gameSocketService.reconnect()
    else:
        ip = SocketService.getIp(GameConfig.game_server_url)
        addr = (ip, GameConfig.game_server_port)
        gameSocketService.connect(addr)
    
    command = Command.LOGIN_USER
    params = 'userkey=' + str(GameConfig.USER_KEY)
    gameSocketService.send(command, params)
    return gameSocketService.receive()